<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" %>
<%@ page import="java.sql.* "%>
<%@ page import="treballfinalUF2.operacionsAmbBBDD" %>
<jsp:useBean id="ObjBdades" scope="session"	class="treballfinalUF2.operacionsAmbBBDD" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="javascripts/funcions_formularis.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Alta alumne</title>
<link HREF="stiles.css" REL="stylesheet" TYPE="text/css" >
</head>
<body>
	<!-- Formulari per alumne-->
	<%
		boolean estatAqui = false;
		
		if (request.getParameter("accio") != null) {
			if (ObjBdades.checkmail(request.getParameter("mailAlumne"))) {//fem aixó si el mail es OK
				if (request.getParameter("nameAlumne").length() < 2 || request.getParameter("passAlumne").length() < 2) out.write("Algun dels camps no és correcte");
				else {
						estatAqui = ObjBdades.insertAlumne(
								ObjBdades.escriuCorrectamentBBDD(request.getParameter("nameAlumne")),
								ObjBdades.escriuCorrectamentBBDD(request.getParameter("passAlumne")),
								ObjBdades.escriuCorrectamentBBDD(request.getParameter("mailAlumne")),
								request.getParameter("grau")
								);
						if(!estatAqui)out.write("El alumne introduit no es pot donar de alta");
				}
			} else {
				out.write("El mail introduit no es correcte");
				estatAqui = false;
			}
			System.out.print(estatAqui);
		}
		
		if (estatAqui == false) {
	%>
	<div style="width:400px;padding-top:30px; height:270px; margin:0 auto; text-align:center; background-color:black;" class="redondear_boders">
		<center>
		<form id="formalumne" method="post" onsubmit="return checkForm1();">
		<table >
			<tr><td><label>Nom alumne:</label></td><td> <input name="nameAlumne" type="text" tabindex="1" id="nomalumne" /></td></tr>
			<tr><td><label>Password:</label></td><td> <input name="passAlumne" type="password" tabindex="2" id="passalumne" /></td></tr>
			<tr><td><label>Mail:</label> </td><td><input name="mailAlumne" type="text" tabindex="2" id="mailalumne" /></td></tr>
			<tr><td><label>Curs:</label></td><td>
				<select name="grau">
					<option>DAW</option>
					<option>ASIX</option>
					<option>DAM</option>
				</select>
			</td></tr>
			<tr><td colspan=2>
			<center><input type="submit" name="accio" value="Dona't d'alta"></center>
			</td></tr>
			</table>
		</form>
		</center>
		<a href="index.jsp">Torna a index</a>
	</div>
	<%
		} else {
			String missatge = "Ja estàs donat d'alta.";
			ObjBdades.setMissatge(missatge);
			response.sendRedirect("confirmaPage.jsp");
		}
	%>
</body>
</html>